<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String ctx = request.getContextPath();
    request.setAttribute("ctx", ctx);
%>
<html>
<head>
    <title>Title</title>
    <script src="${ctx}/bootstrap/jquery-1.9.1.min.js"></script>
    <link rel="stylesheet" href="${ctx}/css/index_work.css">
</head>
<body>
<form action="${ctx}/list.do">
    <input type="hidden" name="pageNum">
    名称：<input type="text" name="title" value="${article.title}">
    内容：<input type="text" name="content" value="${article.content}">
    <input type="submit" value="查询">
    <a href="${ctx}/toadd.do">新增</a>
    <a href="##" onclick="deleteBth()">批量删除</a>
</form>
<table>
    <tr>
        <td>序号><input type="checkbox" onclick="quanx(this)"></td>
        <td>名称</td>
        <td>简介</td>
        <td>内容</td>
        <td>创建时间</td>
        <td>排序</td>
        <td>头像</td>
    </tr>
    <c:forEach items="${pageInfo.list}" varStatus="vs" var="var">
        <tr>
            <td>${vs.index+pageInfo.startRow}<input type="checkbox" name="id" value="${var.id}"/></td>
            <td>${var.title}</td>
            <td>${var.jianjie}</td>
            <td>${var.content}</td>
            <td>${var.create_time}</td>
            <td>${var.paixu}</td>
            <td><img src="${var.img}" style="width: 30px;height: 30px"></td>
        </tr>
    </c:forEach>
</table>
<a href="##" onclick="fenye(1)">首页</a>
<a href="##" onclick="fenye(${pageInfo.prePage})">上一页</a>
<a href="##" onclick="fenye(${pageInfo.nextPage})">下一页</a>
<a href="##" onclick="fenye(${pageInfo.pages})">尾页</a>
共${pageInfo.total}条数据
<script>
    function fenye(pageNum) {
        $("[name='pageNum']").val(pageNum);
        $("form").submit();
    }
    function quanx(obj) {
        $('[name="id"]').prop("checked",$(obj).prop("checked"));
    }
    function deleteBth(id) {
        var ids = new Array();
        $('[name="id"]:checked').each(function () {
            ids.push($(this).val())
        })
        if(confirm("您确定要删除"+ids+"吗？")){
            $.post("${ctx}/deleteBth.do?ids="+ids,function (res) {
                if(res){
                    $("[name='pageNum']").val(1);
                    location.reload();
                }else{
                    alert("删除失败");
                }
            })
        }

    }
</script>
</body>
</html>
